//
// Created by francklinson on 2021/11/5 AT 10:14.
//
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <functional>
#include <climits>
#include <string>

using namespace std;

class Solution {
public:
    int longestSubsequence(vector<int> &arr, int difference) {
        int ans = 0;
        unordered_map<int, int> dp;
        for (int v: arr) {
            dp[v] = dp[v - difference] + 1;
            ans = max(ans, dp[v]);
        }
        return ans;
    }
};

int main() {
    vector<int> arr{1, 5, 7, 8, 5, 3, 4, 2, 1};
    Solution solution;
    cout << solution.longestSubsequence(arr, -2);
    return 0;
}

